<template>
  <div class="order">
    <!-- 面包屑导航 -->
      <bread :item="['订单管理','订单列表']"></bread>
    <!-- 卡片区 -->
    <el-card>
      <!-- 按钮区 -->
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

    <el-table :data="orders" border stripe  height="490">
      <el-table-column type="index" label="序号" width="50"></el-table-column>
      <el-table-column label="订单编号" prop="order_number"></el-table-column>
      <el-table-column label="订单价格" prop="order_price" width="80"></el-table-column>
      <el-table-column label="是否付款" width="80">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.pay_status==='1'" type="success">已付款</el-tag>
          <el-tag v-else type="danger">未付款</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否发货" prop="is_send" width="80"></el-table-column>
      <el-table-column label="下单时间" width="170">
        <template slot-scope="scope">
          {{ scope.row.create_time | dataFormat}}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="130">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" icon="el-icon-edit" @click="editDialog(scope.row.order_id)"></el-button>
          <el-button type="success" size="mini" icon="el-icon-location" @click="locationDialog"></el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页功能 -->
    <el-pagination background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[7, 10, 15, 22]"
      :page-size="queryInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>


    <!-- 修改对话框 -->
    <el-dialog @close="editClose"
      title="提示" width="50%"
      :visible.sync="editShow">

      <el-form :model="addressForm" :rules="addressRules" ref="addressForm" label-width="100px">
        <el-form-item label="省市区/县" prop="addr">
          <el-cascader clearable :props="{expandTrigger:'hover'}" :options="city" v-model="addressForm.addr"></el-cascader>
        </el-form-item>
        
        <el-form-item label="详细地址" prop="street">
          <el-input v-model="addressForm.street"></el-input>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editShow = false">取 消</el-button>
        <el-button type="primary" @click="editSend">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 物流进度 -->
    <el-dialog
      title="物流进度" width="50%"
      :visible.sync="progress">

      <el-timeline>
        <el-timeline-item  type="success " v-for="(item,i) in timeTable" :key="i" :timestamp="item.ftime">{{item.context}}</el-timeline-item>
      </el-timeline>

    </el-dialog>

    </el-card>
  </div>
</template>

<script>
import {bread,default as fn} from "tools"
import city from "./citydata"
export default {
  components:{bread}
 ,data(){return{
   queryInfo:{
     query:""
    ,pagenum:1
    ,pagesize:8
   }
  ,total:0
  ,orders:[]
  ,editShow:false
  ,addressForm:{
    addr:[]
   ,street:""
  }
  ,addressRules:{
    addr:[{required:true,message:"请选择地区",trigger:"blur"}]
   ,street:[{required:true,message:"请填写详细地址",trigger:"blur"}]
  }
 ,city
 ,orderId:null
 ,progress:false
 ,timeTable:[]
 }}
 ,created(){
   this.getOrders()
 }
 ,methods:{
   async getOrders(){
     const {data:ret}= await this.$XHR.get("orders",{params:this.queryInfo})
     if(ret?.meta?.status!==200) return fn.mg("error","获取失败")
     this.total= ret?.data?.total ? ret.data.total : 0
     this.orders= ret?.data?.goods ? ret.data.goods : 0
   }
  ,handleSizeChange(n){
    this.queryInfo.pagesize= n
    this.getOrders()
  }
  ,handleCurrentChange(n){
    this.queryInfo.pagenum=n
    this.getOrders()
  }
  ,async editDialog(n){
    this.orderId= n
    this.editShow= true
  }
  ,editClose(){
    this.$refs['addressForm'].resetFields()
  }
  ,editSend(){
    this.$refs['addressForm'].validate(async h=>{
      if(!h)return
      fn.mg(null,"暂未开通")
    })
  }
  ,async locationDialog(){
    const {data:ret}= await this.$XHR.get("/kuaidi/804909574412544580")
    if(ret?.meta?.status!==200) return fn.mg("error","获取失败")
    this.timeTable= ret?.data ? ret.data :[]
    this.progress= true
  }
 }
}
</script>

<style lang="less" scoped>

</style>